import axios from 'axios'
import { Message, MessageBox } from 'element-ui'
/*错误处理*/
const errorHandle = function(err){
    switch (err.status){
        default:{
            let msg = err.status+':'+err.message
            Message.error(msg)
            break;
        }
        //
    }

};
const baseUrl1 = "http://dev.solarpv.top";
const baseUrl2 = "http://core.solarpv.top";

// 创建axios实例
const service = axios.create({
    timeout: 50000 ,// 请求超时时间
})

// request拦截器
service.interceptors.request.use(config => {
    return config
}, error => {
    // Do something with request error
    console.log(error) // for debug
    Promise.reject(error)
})

// respone拦截器
service.interceptors.response.use(
    response => {
        let res = response.data;
        if(res.status == 200){
            return Promise.resolve(res.data)
        }else{
            errorHandle(res);
            return Promise.reject(res)
        }
    },
    error => {
        let err = {status:500,message:'系统错误，请稍后重试！'}
        errorHandle(err);
        return Promise.reject(err)
    }
);
//桌面端登录
export function login(data) {
    let newData = Object.assign({source:'su'}, data);
    return service({
        baseURL: baseUrl1,
        url:'/api/client/auth/login',
        method:'post',
        data:newData

    })
}

//获取图片验证码
export function validateCode() {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/auth/validateCode',
        method:'get',

    })
}

//获取版本号
export function getVersion() {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/version',
        method:'get',

    })
}

//新建工程
export function addProject(data) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/project/new',
        method:'post',
        data

    })
}

//查询工程列表
export function getProjectList(params) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/project/list',
        method:'get',
        params

    })
}

//删除工程
export function delProjectItem(data) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/project/delete',
        method:'post',
        data
    })
}

//修改工程分享状态
export function updateShare(data) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/project/updateShare',
        method:'post',
        data
    })
}

//获取大洲列表
export function getContinent () {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/address/continent',
        method:'get',
    })
}

//获取国家列表
export function getCountry (params) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/address/country',
        method:'get',
        params
    })
}

//获取省份列表
export function getProvince (params) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/address/province',
        method:'get',
        params
    })
}

//获取城市列表
export function getCity (params) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/address/city',
        method:'get',
        params
    })
}

//获取地面类型及反射率列表
export function getGroundType() {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/ground/type',
        method:'get',
    })
}

//获取气象数据
export function getMeteorData(params) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/meteor/data',
        method:'get',
        params
    })
}

//获取时区
export function getTimezone(params) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/timezone',
        method:'get',
        params
    })
}


//获取下拉项列表 通用
export function getDownList(params) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/common/dict',
        method:'get',
        params
    })
}

//查询工程详情基本数据
export function getDetailBasic(params) {
    return service({
        baseURL: baseUrl1,
        url:'/api/client/project/detail/basic',
        method:'get',
        params
    })
}

//更新工程信息
export function updateProject(data) {
    let newData = Object.assign({source:'su'}, data);
    return service({
        baseURL: baseUrl1,
        url:'/api/client/project/update',
        method:'post',
        data:newData
    })
}

//KT算法计算全年最佳倾角
export function getSlopeYear(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/slope_year',
        method:'get',
        params
    })
}

//斜单轴最佳倾角
export function getSlopeVertical(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/Vertical_slope',
        method:'get',
        params
    })
}

//获取厂商列表
export function getCompanyList(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/company/list',
        method:'get',
        params
    })
}

//获取组件列表
export function getComponentList(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/component/list',
        method:'get',
        params
    })
}

//获取组件详情
export function getComponentInfo(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/component/detail',
        method:'get',
        params
    })
}

//倾角对辐照度影响分析图（全年）
export function getSlopeYearTu(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/slope_year_tu',
        method:'get',
        params
    })
}

//方位角对辐照度影响分析图（全年）
export function getSaaYearTu(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/saa_year_tu',
        method:'get',
        params
    })
}

//查询工程详情组件信息
export function getProjectComponent(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/project/detail/component',
        method:'get',
        params
    })
}

//获取组件IV曲线
export function getWucanshu(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/wucanshu',
        method:'get',
        params
    })
}

//查询组件参数信息
export function getDetailWithName(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/component/detailWithName',
        method:'get',
        params
    })
}

//查询建议间距
export function getJianju(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/jianju',
        method:'get',
        params
    })
}

//KT算法计算夏季最佳倾角
export function getSlopeSummer(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/slope_summer',
        method:'get',
        params
    })
}

//KT算法计算冬季最佳倾角
export function getSlopeWinter(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/slope_winter',
        method:'get',
        params
    })
}

//KT算法计算自定义月份最佳倾角
export function getSlopeChoose(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/slope_choose',
        method:'get',
        params
    })
}

//获取逆变器列表
export function getInverterList(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/inverter/list',
        method:'get',
        params
    })
}

//获取逆变器详细信息
export function getInverterInfo(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/inverter/detail',
        method:'get',
        params
    })
}

//获取逆变器参数
export function getInverterParams(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/inverter/detailWithName',
        method:'get',
        params
    })
}

//获取组件串联下拉选项
export function getChuanlianOption(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/chuanlian',
        method:'get',
        params
    })
}

//获取逆变器性能曲线
export function getEffInverterXinglengTu(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/EffInverter_tu',
        method:'get',
        params
    })
}
//获取所需逆变器个数以及串并联组件数
export function getChuanbinglianParam(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/chuanbinglian',
        method:'get',
        params
    })
}

//查询工程详情逆变器信息
export function getProjectInverter(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/project/detail/inverter',
        method:'get',
        params
    })
}

//获取工程文件线缆信息
export function getInverterPerformanceCurve(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/inverter/performanceCurve',
        method:'get',
        params
    })
}

//获取工程文件线缆信息
export function getProjectCable(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/project/detail/cable',
        method:'get',
        params
    })
}

//获取工程文件损失信息
export function getProjectLossCount(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/project/detail/loss',
        method:'get',
        params
    })
}

//获取逆变器全年负荷曲线及超配损失等参数-固定
export function getInverterChaopei(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/chaopei',
        method:'get',
        params
    })
}

//获取逆变器全年负荷曲线及超配损失等参数-东西轴向单轴跟踪
export function getInverterChaopeiEw(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/chaopei_ew',
        method:'get',
        params
    })
}

//获取逆变器全年负荷曲线及超配损失等参数-南北轴向单轴跟踪
export function getInverterChaopeiNs(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/chaopei_ns',
        method:'get',
        params
    })
}

//获取逆变器全年负荷曲线及超配损失等参数-斜单轴
export function getInverterChaopeiVertical(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/chaopei_vertical',
        method:'get',
        params
    })
}

//获取逆变器全年负荷曲线及超配损失等参数-双轴
export function getInverterChaopeiDouble(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/chaopei_double',
        method:'get',
        params
    })
}

//入射角损失图
export function getLossBo(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/bo',
        method:'get',
        params
    })
}


//集中式逆变器 - 光伏组串至直流汇流箱   组串式逆变器 - 光伏组串至组串式逆变器  -  长度
export function getzujianLen(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/Length_jizhong_direct_zujian',
        method:'get',
        params
    })
}

//集中式逆变器 - 直流汇流箱至集中式逆变器 —长度
export function getHuiliuxiangLen(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/Length_jizhong_direct_huiliuxiang',
        method:'get',
        params
    })
}

//组串式逆变器 - 组串式逆变器至交流汇流箱 — 长度
export function getAlternatingLen(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/Length_zuchuan_alternating',
        method:'get',
        params
    })
}

//组串式逆变器 - 交流汇流箱至箱变 — 长度
export function getXiangbianLen(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/Length_zuchuan_alternating_xiangbian',
        method:'get',
        params
    })
}

//集中式逆变器 - 光伏组串至直流汇流箱 - 压降
export function getDropJizhongDirectZujian(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/Drop_jizhong_direct_zujian',
        method:'get',
        params
    })
}

//获取集中式逆变器 - 直流汇流箱 至 集中式逆变器——压降
export function getDropJizhongDirectHuiliuxiang(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/Drop_jizhong_direct_huiliuxiang',
        method:'get',
        params
    })
}
//获取组串式逆变器 - 组串式逆变器 至 交流汇流箱——压降
export function getDropZuchuanAlternating(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/Drop_zuchuan_alternating',
        method:'get',
        params
    })
}

//获取组串式逆变器 - 交流汇流箱 至 箱变——压降
export function getDropZuchuanAlternatingXiangbian(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/Drop_zuchuan_alternating_xiangbian',
        method:'get',
        params
    })
}

//获取仿真报告-固定倾角_组串式
export function getFZBGGgudingZuchuan(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/FZBG_guding_zuchuan',
        method:'get',
        params
    })
}

//获取仿真报告-东西_组串式
export function getFZBGEwZuchuan(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/FZBG_ew_zuchuan',
        method:'get',
        params
    })
}

//获取仿真报告-南北_组串式
export function getFZBGNsZuchuan(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/FZBG_ns_zuchuan',
        method:'get',
        params
    })
}

//获取仿真报告-双轴_组串式
export function getFZBGDoubleZuchuan(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/FZBG_double_zuchuan',
        method:'get',
        params
    })
}

//获取仿真报告-斜单轴_组串式
export function getFZBGVerticalZuchuan(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/FZBG_vertical_zuchuan',
        method:'get',
        params
    })
}


//获取仿真报告-固定倾角_集中式
export function getFZBGGudingJizhong(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/FZBG_guding_jizhong',
        method:'get',
        params
    })
}

//获取仿真报告-东西_集中式
export function getFZBGEwJizhong(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/FZBG_ew_jizhong',
        method:'get',
        params
    })
}

//获取仿真报告-南北_集中式
export function getFZBGNsJizhong(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/FZBG_ns_jizhong',
        method:'get',
        params
    })
}

//获取仿真报告-双轴_集中式
export function getFZBGDoubleJizhong(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/FZBG_double_jizhong',
        method:'get',
        params
    })
}

//获取仿真报告-斜单轴_集中式
export function getFZBGVerticalJizhong(params) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/FZBG_vertical_jizhong',
        method:'get',
        params
    })
}



//获取获取汇流箱列表
export function getComboboxList(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/combobox/list',
        method:'get',
        params
    })
}

//获取电缆型号列表
export function getCableList(params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/cable/list',
        method:'get',
        params
    })
}

//获取电缆型号列表-不需要汇流箱
export function getCableListNoCombobox (params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/cable/list/no-combobox',
        method:'get',
        params
    })
}

//获取工程全部详细信息
export function getProjectDetail (params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/project/detail',
        method:'get',
        params
    })
}

//提交幅照数据
export function postProjectDetailBasic (data) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/project/sync',
        method:'post',
        data
    })
}

//提交截图数据
export function postProjectScreenshots (data) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/project/screenshots',
        method:'post',
        data
    })
}

//获取幅照数据
export function getProjectDetailBasic (params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/project/sync',
        method:'get',
        params
    })
}

//获取截图数据
export function getProjectScreenshots (params) {
    return service({
        baseURL:baseUrl1,
        url:'/api/client/project/screenshots',
        method:'get',
        params
    })
}

//考虑阴影后的辐照量计算-固定
export function getShadowGuding (data) {
    return service({
        baseURL:baseUrl2,
        url:'/api/values/shadow_guding',
        method:'post',
        data
    })
}